home *** CD-ROM | disk | FTP | other *** search
/ Champak 109 / Vol 109.iso / games / bubble_t.swf / scripts / frame_1 / DoAction_3.as < prev    next >
Text File  |  2008-11-12  |  3KB  |  145 lines

  1. function checkMatch(vBubble)
  2. {
  3.    gGroup = [vBubble];
  4.    gStranded = new Array();
  5.    vBubble.pGroupIndex = 0;
  6.    searchMatch(vBubble,gGroup,vBubble.bubble._currentFrame);
  7.    if(2 < gGroup.length)
  8.    {
  9.       gStranded = getStranded();
  10.       gMode = cREMOVE;
  11.       gUnitScore = 2;
  12.       gMatchScore = 0;
  13.       gBonus = 1;
  14.       gTopLevel = 1000;
  15.       return true;
  16.    }
  17.    gMode = cNORMAL;
  18.    return false;
  19. }
  20. function searchMatch(vBubble, vGroup, vType)
  21. {
  22.    var i = 0;
  23.    while(i < 6)
  24.    {
  25.       var lPos = getNeighborPos(vBubble,i);
  26.       var b = getBubbleAt(lPos.r,lPos.c);
  27.       if(b != 0 && b != -1)
  28.       {
  29.          if(vType)
  30.          {
  31.             if(!hasAt(vGroup,b,b.pGroupIndex))
  32.             {
  33.                if(b.bubble._currentFrame == vType)
  34.                {
  35.                   vGroup.push(b);
  36.                   b.pGroupIndex = vGroup.length - 1;
  37.                   searchMatch(b,vGroup,vType);
  38.                }
  39.             }
  40.          }
  41.          else if(!hasAt(vGroup,b,b.pStrandedIndex))
  42.          {
  43.             if(!hasAt(gGroup,b,b.pGroupIndex))
  44.             {
  45.                vGroup.push(b);
  46.                b.pStrandedIndex = vGroup.length - 1;
  47.                searchMatch(b,vGroup,vType);
  48.             }
  49.          }
  50.       }
  51.       i++;
  52.    }
  53. }
  54. function getStranded()
  55. {
  56.    gStranded = new Array();
  57.    var r0 = 0;
  58.    var c0 = -1;
  59.    var lDir = 5;
  60.    var lPoint = {r:r0,c:c0};
  61.    gEdgeGroup = new Array();
  62.    while(true)
  63.    {
  64.       while(true)
  65.       {
  66.          do
  67.          {
  68.             lDir = turnDir(lDir,1);
  69.             var lPos = dirToGrid(lDir);
  70.             var r = lPoint.r + lPos.dr;
  71.             var c = lPoint.c + lPos.dc;
  72.          }
  73.          while(r < 0);
  74.          
  75.          var b = getBubbleAt(r,c);
  76.          var lStop = false;
  77.          if(b == 0 || b == -1)
  78.          {
  79.             lStop = true;
  80.          }
  81.          else if(hasAt(gGroup,b,b.pGroupIndex))
  82.          {
  83.             lStop = true;
  84.          }
  85.          if(lStop)
  86.          {
  87.             lPoint.r = r;
  88.             lPoint.c = c;
  89.             lDir = turnDir(lDir,-2);
  90.             break;
  91.          }
  92.          gEdgeGroup.push(b);
  93.          b.pEdgeGroupIndex = gEdgeGroup.length - 1;
  94.       }
  95.       if(Math.ceil(r / 2) + gRowLength - 1 < c)
  96.       {
  97.          break;
  98.       }
  99.    }
  100.    var i = 0;
  101.    while(i < gGroup.length)
  102.    {
  103.       var j = 0;
  104.       while(j < 6)
  105.       {
  106.          var lPos = getNeighborPos(gGroup[i],j);
  107.          var b = getBubbleAt(lPos.r,lPos.c);
  108.          if(b != 0 && b != -1)
  109.          {
  110.             if(!hasAt(gGroup,b,b.pGroupIndex))
  111.             {
  112.                if(!hasAt(gEdgeGroup,b,b.pEdgeGroupIndex))
  113.                {
  114.                   if(!hasAt(gStranded,b,b.pStrandedIndex))
  115.                   {
  116.                      gStranded.push(b);
  117.                      b.pStrandedIndex = gStranded.length - 1;
  118.                      searchMatch(b,gStranded,0);
  119.                   }
  120.                }
  121.             }
  122.          }
  123.          j++;
  124.       }
  125.       i++;
  126.    }
  127.    return gStranded;
  128. }
  129. function hasAt(vArray, vMember, vIndex)
  130. {
  131.    if(vIndex == undefined)
  132.    {
  133.       return false;
  134.    }
  135.    if(vIndex >= vArray.length)
  136.    {
  137.       return false;
  138.    }
  139.    if(vMember == vArray[vIndex])
  140.    {
  141.       return true;
  142.    }
  143.    return false;
  144. }
  145.